/**
 * Created by Administrator on 2017/2/18.
 */

import React, {Component, PropTypes} from 'react';
import {Header} from '../header/header';
import {BtnBottom} from '../prodcut/productDetails'
import {getQueryString} from '../../scripts/url';
import {initFunction} from '../../scripts/tip';
import {inintTicket,testTicket} from '../../scripts/voucher';


export default class Voucher extends Component {
    componentDidMount() {

        var url=location.href;

        //TODO getProductId
        var productId=getQueryString("productId",url);
        var productDetailId=getQueryString("productDetailId",url);
        var count=getQueryString("count",url);

        inintTicket(productId,productDetailId,count);
        initFunction();


        $('.VoucherId .btn').click(function(){

            var voucherSecret=$('.VoucherId input').val();
            var voucherId=$('.list-item.select').attr('voucherId');
            testTicket(productId,voucherSecret,voucherId,productDetailId,count)
        });


        $('.Voucher .useBtn').click(function(){

            var voucherSecret1=$('.list-item.select .voucherSecret').html();
            var voucherId1=$('.list-item.select').attr('voucherId');

            testTicket(productId,voucherSecret1,voucherId1,productDetailId,count)
        });


    }

    render(){
        return <div className="Voucher">
            <Header headerTitle="使用抵用券"  className="back"/>
           <div className="main fadeaction">
               <VoucherId />
               <VoucherTicket />
           </div>
            <BtnBottom btnTitle='使用'className="useBtn"/>
        </div>
    }

}

export  class VoucherId extends Component {
    render(){
        return <div className="VoucherId">
            <div className="editId">
                <input placeholder="输入抵用券兑换"/>
            </div>
            <div className="btn">
                <a>兑换</a>
            </div>
        </div>
    }
}

export  class VoucherTicket extends Component {
    componentDidMount() {

    }

    render(){
        return <div className="VoucherTicket">
            <ul>
            </ul>
        </div>
    }
}